package org.example.network.high.uri;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;

public class URITests {
    public static void main(String[] args) throws IOException {
        URI uri = URI.create("https://www.baidu.com");
        URL url = uri.toURL();
        URLConnection urlConnection = url.openConnection();
        urlConnection.connect();
        try(InputStream inputStream = urlConnection.getInputStream()){
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            reader.lines().forEach(System.out::println);
        }

        // 也可以直接通过URL打开一个InputStream
        try (InputStream inputStream = url.openStream()) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
            reader.lines().forEach(System.out::println);
        }
    }
}
